
require('./running.less')
require('../../assets/fonts/iconfont.css')

// 引入文档加载事件，dom选择器封装
let { $, $$, $$$ } = require('../../utils/dom')
//引入axios
const axios = require('../../utils/axios')

//引入顶部导航
const navTop = require('../../utils/nav-top')
navTop.showNavTop('running');

//引入底部导航
const nav = require('../../utils/nav')
nav.showNav('sports');


$(function () {
  /**
   * 查询运动数据
   */
  axios.get("/api/exercise").then(function (res) {
    if (res.data.errno === 0) {
      $$("#kilometer").textContent = (res.data.data.sum7Meter / 1000.).toFixed(1)
    }
  })
  /**
   * 初始化高德插件
   */
  var map = new AMap.Map('container', {
    zoom: 15,//级别
    center: [104.05603, 30.538176],//中心点坐标
    viewMode: '3D'//使用3D视图
  });
  var marker = new AMap.Marker({
    position: new AMap.LngLat(104.05603, 30.538176),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
    title: '起点'
  });

  // 将创建的点标记添加到已有的地图实例：
  map.add(marker);

  /**
   * 开始运动点击事件
   */
  let mask = $$("#mask");
  let donNum = $$("#num")
  let num = parseInt(donNum.textContent)
  $$("#go").addEventListener("click", function () {
    setInterval(function name(params) {
      if (num == 0) {
        donNum.textContent = "GO"
        location.href = "./sporting.html#跑步"
      } else {
        mask.style.display = "block"
        donNum.textContent = num--;
      }
    }, 1000)
  })
  /**
   * 点击跳转
   */
  $$("#line").addEventListener("click",function () {
    location.href = "./line.html#1"
  })
})
